﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OntologyUtility;
using OntologyFormDesigner.GuiComponent;


namespace OntologyFormDesigner
{
    public partial class OntologiesChoose : OntologyFormDesigner.GuiComponent.WizardPanel
    {
        public OntologiesChoose(WizardForm form, Control control)
            : base(control)
        {
            this.Parent = form;
            InitializeComponent();
        }

        private void treeView1_AfterSelect(object sender, TreeNodeMouseClickEventArgs e)
        {
            
            try
            {
                selectedNode = ((TreeView)sender).SelectedNode;
                //MessageBox.Show(selectedNode.ToString());
                if (this.ObjectWizard is OntologyUtility.Interfaces.IOrWidget)
                {
                    if (((Node)((TreeView)sender).SelectedNode.Tag).Type.Equals("OrType"))
                    {
                        this.PageComplete = true;
                        this.canFlipToNextPage();
                        this.NextPage.ObjectWizard = ((TreeView)sender).SelectedNode.Tag;
                    }
                    else
                    {
                        MessageBox.Show("Il nodo selezionato non è compatibile con la widget corrente (OrWidget)");
                        this.PageComplete = false;
                        this.canFlipToNextPage();
                        Parent.DisableNext();
                    }
                }
                else if (this.ObjectWizard is OntologyUtility.Interfaces.IAlternativeWidget)
                {
                    if (((Node)((TreeView)sender).SelectedNode.Tag).Type.Equals("AlternativeType"))
                    {
                        this.PageComplete = true;
                        this.canFlipToNextPage();
                        this.NextPage.ObjectWizard = ((TreeView)sender).SelectedNode.Tag;
                    }
                    else
                    {
                        MessageBox.Show("Il nodo selezionato non è compatibile con la widget corrente (AlternativeWidget)");
                        this.PageComplete = false;
                        this.canFlipToNextPage();
                        Parent.DisableNext();
                    }
                }
            }
            catch (Exception)
            {
                this.PageComplete = false;
                this.canFlipToNextPage();
                Parent.DisableNext();
               //MessageBox.Show("xc :" + ex.ToString());
            }
            /*else
                MessageBox.Show("Il nodo selezionato non è compatibile con la widget corrente");*/
        }


    }
}
